/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upn.sigemfi.rec.bc;

import edu.upn.sigemfi.rec.be.Credito;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Diego
 */
@Stateless
public class CreditoFacade implements CreditoFacadeLocal {

    @PersistenceContext
    private EntityManager em;

    public void create(Credito credito) {
        em.persist(credito);
    }

    public void edit(Credito credito) {
        em.merge(credito);
    }

    public void remove(Credito credito) {
        em.remove(em.merge(credito));
    }

    public Credito find(Object id) {
        return em.find(Credito.class, id);
    }

    public List<Credito> findAll() {
        return em.createQuery("select object(o) from Credito as o").getResultList();
    }

    public List<Credito> findAllVigentes() {
        return em.createQuery("select object(o) from Credito as o where o.fidRecCartera.idCartera = 1").getResultList();
    }

    public List<Credito> findAllVencidos() {
        return em.createQuery("select object(o) from Credito as o where o.fidRecCartera.idCartera = 2").getResultList();
    }

    public List<Credito> findAllRefinanciados() {
        return em.createQuery("select object(o) from Credito as o where o.fidRecCartera.idCartera = 3").getResultList();
    }

    public List<Credito> findAllPrejudiciales() {
        return em.createQuery("select object(o) from Credito as o where o.fidRecCartera.idCartera = 4").getResultList();
    }

    public List<Credito> findAllJudiciales() {
        return em.createQuery("select object(o) from Credito as o where o.fidRecCartera.idCartera = 5").getResultList();
    }

    public List<Credito> findAllCastigados() {
        return em.createQuery("select object(o) from Credito as o where o.fidRecCartera.idCartera = 6").getResultList();
    }

    public List<Credito> findAllCancelados() {
        return em.createQuery("select object(o) from Credito as o where o.fidRecCartera.idCartera = 7").getResultList();
    }
}
